package com.jams.goodox.listen;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.jams.goodox.SePref;
import com.jams.goodox.activity.wallet.SetPayPasswordActivity;

/**
 * Created by Jin on 2017/1/10.
 * Description 校验支付密码是否设置
 */
public class CheckPayPassword {

	private Activity activity;

	// 来自哪个Activity的请求
	private int come;

	public CheckPayPassword(Activity activity, int come) {
		this.activity = activity;
		this.come = come;
	}

	/**
	 * 检查是否设置密码
	 */
	public boolean checkHasSetPassword() {
		// 是否设置支付密码
		if (!hasSetPayPassword()) {
			goSetPasswordDialog();
			return false;
		}
		return true;
	}

	/**
	 * 去设置密码弹窗
	 */
	private void goSetPasswordDialog() {
		new MaterialDialog.Builder(activity).content("您尚未设置支付密码，请先去设置")
				.positiveText("去设置").onPositive(new MaterialDialog.SingleButtonCallback() {
			@Override
			public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
				goSetPassword();
			}
		}).negativeText("取消").onNegative(new MaterialDialog.SingleButtonCallback() {
			@Override
			public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
				dialog.dismiss();
			}
		}).show();
	}

	/**
	 * 去设置密码
	 */
	public void goSetPassword() {
		Intent i = new Intent(activity, SetPayPasswordActivity.class);
		Bundle b = new Bundle();
		b.putInt("come", come);
		i.putExtras(b);
		activity.startActivity(i);
	}

	/**
	 * 是否设置支付密码
	 */
	private boolean hasSetPayPassword() {
		return SePref.isSetPayPwd();
	}
}
